package MyThread;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: AliceMana
 * Date: 2022-12-30
 * Time: 16:51
 */
public class ThreadDemo10 {
    public static void main(String[] args) throws InterruptedException {
        Thread t = new Thread( () -> {
            for (int i = 0; i < 3; i++) {
                System.out.println("hello thread");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
        });
        t.start();

        // join执行之前, t线程已经执行结束, join操作不会阻塞, 会立即返回
        Thread.sleep(5000);

        System.out.println("join之前");
        // 让当前的main线程等待t线程执行结束(等待t的run执行完)
        t.join();
        System.out.println("join之后");
    }
}
